package com.sm.utils;

import com.sm.config.JwtConfig;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Configuration
public class JwtUtils {

	@Autowired
	private JwtConfig jwtConfig;

	public String createToken(Long userId) {
		String secretKey = jwtConfig.getSecretKey();
		long expiration = jwtConfig.getExpiration();

		Map<String, Object> claims = new HashMap<>();
		claims.put("userId", userId);

		return Jwts.builder()
				.signWith(SignatureAlgorithm.HS256, secretKey)
				.setClaims(claims)
				.setExpiration(new Date(System.currentTimeMillis() + expiration))
				.compact();
	}
}
